package com.enjoy.concurrent.ch1;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

@Slf4j
public class SynTest {
    private static final Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            synchronized (lock) {
                try {
                    lock.wait();
                    log.info("执行了");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t1").start();

        Thread.sleep(1000);

        new Thread(() -> {
            synchronized (lock) {
                try {
                    lock.wait();
                    log.info("执行了");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t2").start();

        Thread.sleep(1000);

        new Thread(() -> {
            synchronized (lock) {
                lock.notifyAll();
                log.info("执行了");
            }
        }, "t3").start();

    }

    @Test
    public void test1() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(100000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t1");

        t1.start();

        t1.interrupt();

        Thread.sleep(1000000);

    }


}
